package com.kingmed.kmss.api.internal;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.kingmed.kmss.common.dto.kmcs.*;
import com.kingmed.kmss.common.vo.CommonPage;
import com.kingmed.kmss.common.vo.CommonResponse;
import com.kingmed.kmss.common.vo.CommonResponseHelper;
import com.kingmed.kmss.framework.feign.client.kmcs.MsFeignServiceFacade;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 仅用于内部，给前端提供的通用型接口，因此不写在各自微服务里
 * 此类接口不涉及权限注解！如果涉及要控制权限，必须写在对应的微服务controller层，并加上权限注解
 * 强制：只能调用framework-feign里的client，不允许添加任何业务逻辑，业务逻辑必须写在facade
 * </p>
 */
@RestController
@RequestMapping("/int/kmcs/ms")
@Api(tags = "crm使用-KMCS营销相关公共接口")
public class KmcsMsApiController {

    @Autowired
    private MsFeignServiceFacade msFeignServiceFacade;

    @ApiOperation("物价级别、物价版本信息")
    @PostMapping(value = "/itemPrice")
    public CommonResponse<List<KmcsPriceDTO>> itemPrice(@RequestBody KmcsPriceQueryDTO queryDTO) {
        return CommonResponseHelper.success(msFeignServiceFacade.handKmcsPrice(queryDTO));
    }

    @ApiOperation("套餐列表信息（前n条数据）")
    @PostMapping(value = "/kmcsMp")
    public CommonResponse<List<KmcsMpDTO>> kmcsMp(@Validated @RequestBody KmcsMpQueryDTO queryDTO) {
        return CommonResponseHelper.success(msFeignServiceFacade.handKmcsMp(queryDTO));
    }

    @ApiOperation("套餐(项目)列表信息")
    @PostMapping(value = "/kmcsMpProd")
    public CommonResponse<List<KmcsMpProdDTO>> kmcsMpProd(@RequestBody KmcsMpProdQueryDTO queryDTO) {
        return CommonResponseHelper.success(msFeignServiceFacade.kmcsMpProd(queryDTO));
    }

    @ApiOperation("套餐列表信息（分页）")
    @PostMapping(value = "/kmcsMpPage")
    public CommonResponse<CommonPage<KmcsMpDTO>> kmcsMpPage(@Validated @RequestBody KmcsMpQueryDTO queryDTO) {
        return CommonResponseHelper.success(msFeignServiceFacade.kmcsMpPage(queryDTO));
    }

    @ApiOperation("医院收费、省三级收费标准")
    @PostMapping(value = "/feeStandard")
    public CommonResponse<KmcsFeeDTO> feeStandard(@RequestBody KmcsFeeQueryDTO queryDTO) {
        queryDTO.setMpIds(Collections.singletonList(queryDTO.getMpId()));
        queryDTO.setMpId(StrUtil.EMPTY);
        List<KmcsFeeDTO> dtoList = msFeignServiceFacade.handKmcsFee(queryDTO);
        return CommonResponseHelper.success(CollectionUtils.isNotEmpty(dtoList) ? dtoList.get(0) : null);
    }

    @ApiOperation("根据 mpId 查询医院收费、省三级收费标准")
    @PostMapping(value = "/feeStandardByMpId")
    public CommonResponse<List<KmcsFeeDTO>> feeStandardByMpId(@RequestBody KmcsFeeQueryDTO queryDTO) {
        List<KmcsFeeDTO> dtoList = msFeignServiceFacade.handKmcsFeeByMpId(queryDTO);
        return CommonResponseHelper.success(CollectionUtils.isNotEmpty(dtoList) ? dtoList : null);
    }

    @ApiOperation("医院收费、省三级收费标准（批量）")
    @PostMapping(value = "/feeStandardBatch")
    public CommonResponse<List<KmcsFeeDTO>> feeStandardBatch(@RequestBody KmcsFeeQueryDTO queryDTO) {
        queryDTO.setMpId(StrUtil.EMPTY);
        return CommonResponseHelper.success(msFeignServiceFacade.handKmcsFee(queryDTO));
    }

}
